package kafka;

import com.google.gson.Gson;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.junit.Test;
import streamLogStaticJava.pojos.logbean;

import java.sql.Timestamp;
import java.util.Date;
import java.util.Properties;

/**
 * @ClassName kafkaProductor
 * @Description TODO
 * @Author dalong
 * @Date 2020/7/20 22:14
 * @Version 1.0
 **/

public class kafkaProductor {

    public static void main(String[] args) {

        String topic = "click_events";
        Properties properties = new Properties();
        properties.setProperty("bootstrap.servers","localhost:9092");
        properties.setProperty("group.id","weblog");
        properties.setProperty("key.serializer.class","org.apache.kafka.common.serialization.StringSerializer");
        properties.setProperty("value.serializer.class","org.apache.kafka.common.serialization.StringSerializer");

        KafkaProducer<String, String> product = new KafkaProducer<String, String>(properties);

        Gson gson = new Gson();
        while(true){
            Date date = new Date();
            long time = date.getTime();

            logbean logbean = new logbean();
            ProducerRecord<String, String> stringStringProducerRecord = new ProducerRecord<String, String>(topic,gson.toJson(logbean));
            product.send(stringStringProducerRecord);
        }

    }


    @Test
    public void test(){

        System.out.println((int)(Math.random()*1000)%3);
    }
}
